package com.hpeu_01.day0112.homework;

import java.util.Scanner;

/**
 * 第二题：接收键盘输入，检测年龄不能为负数和大于150岁。
 * （要求：使用throw抛出Exception异常，使用try-catch捕获并处理异常）
 */
public class HomeWork02 {
    public static void main(String[] args) {
        Throw02 throw02 = new Throw02();
        try {
            throw02.method();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}
class Throw02 {
    public void method() throws Exception {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入年龄：");
        int age = scanner.nextInt();
        if (age<=0||age>150){
            throw new Exception("你输入的年龄错误");
        }
        System.out.println("你的年龄为"+age);
    }
}